﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Products : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection();
    SqlDataAdapter da;
    DataSet ds;
    SqlCommandBuilder cb;
    DataTable dt;
    DataView dv;
    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeADObject_Product();
        LoadProductInfo();
    }

    void InitializeADObject_Product()
    {

        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        con.ConnectionString = constr;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "LoadProductTable";

        da = new SqlDataAdapter(cmd);
        cb = new SqlCommandBuilder(da);

        ds = new DataSet();
        da.FillSchema(ds, SchemaType.Mapped);
        da.Fill(ds, "Production.Products");
    }
    void LoadProductInfo()
    {

        dt = ds.Tables["Production.Products"];
        dv = new DataView(dt);
        da.Fill(dt);

        gvProducts.AutoGenerateSelectButton = true;
        gvProducts.AllowPaging = true;
        gvProducts.PageSize = 5;

        gvProducts.DataSource = dt;
        gvProducts.DataBind();
     
    }
    protected void gvProducts_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvProducts.PageIndex = e.NewPageIndex;
        gvProducts.DataBind();
    }
}
